/*	How to use it:
 * 	
 *	copy these lines, to your class and call them insted of "trace()"	=)
 */
//	import	dk.lbi.att.Att;
//	//	normal message			balck	white
//	private	function	onTrace(...args):void{Att.send('onTrace',String(Object(this).constructor),args);}
//	//	error message			red		bold
// 	private	function	eTrace(...args):void{Att.send('eTrace',String(Object(this).constructor),args);}
//	//	warning message			orange	bold
//	private	function	wTrace(...args):void{Att.send('wTrace',String(Object(this).constructor),args);}
//	//	highlighted message		white	bold
//	private	function	hTrace(...args):void{Att.send('hTrace',String(Object(this).constructor),args);}
//
//	//	and also 			g-green	b-blue	y-yellow	m-magenta	c-cyan	s-silver	colors can be used	(all bold)
//	//	or one of these: 	gTrace 	bTrace	yTrace		mTrace		cTrace	sTrace
/*
 * 
 */  
package com.tools.traceTool
{
	import flash.events.AsyncErrorEvent;
	import flash.events.SecurityErrorEvent;
	import flash.events.StatusEvent;
	import flash.events.TimerEvent;
	import flash.net.LocalConnection;
	import flash.utils.Timer;	
// DEF ###################// DEF #####################################################blic		static	const	SIGN:uint=500;
//	protected	static	const	CONNECTION_ID:String='_AdvancedTracingTool_2AnyURL_by_pptthh';
	protected	static	const	CONNECTION_ID:String='_RemoteTraceConnectionId_2AnyURL_by_ppy@LBi';
	protected 	static	var		localConnection:LocalConnection=new LocalConnection();
	private 	static	var		isFirst:Boolean=true;
	private		static	const	ALLOW_DOMAIN:String='*'
	private		static	const	ALLOW_DOMAIN_HOST:String='localhost'
// DEF #####################################################
public	function	Att(){}
//	it handels everiting with the sending trace() information throung Local Connection
public	static	function	send(CalledMethodName:String,...args):void
{
	var	className:String=args.shift();
	args=String(args).split('\n');
	for(var i:uint=args.length;i--;){sendSL(CalledMethodName,className,String(args.shift()));}
}
//	send a Signle Line, line brakes are removed!
public	static	function	sendSL(CalledMethodName:String,...args):void
{
	localConnection.allowDomain(		ALLOW_DOMAIN, ALLOW_DOMAIN_HOST);
	localConnection.allowInsecureDomain(ALLOW_DOMAIN, ALLOW_DOMAIN_HOST);
	localConnection.addEventListener(StatusEvent.STATUS,				onStatus);
	localConnection.addEventListener(AsyncErrorEvent.ASYNC_ERROR,		onAsyncError);
	localConnection.addEventListener(SecurityErrorEvent.SECURITY_ERROR,	onSecurityError);
	isFirst?runOnce():null;
	args.length>1?
		localConnection.send(CONNECTION_ID,CalledMethodName,args.shift(),args):
		localConnection.send(CONNECTION_ID,CalledMethodName,args);
}
// Private #################################################
//	to make a signal for chacking the connection...
private	static	function	runOnce():void
{
	isFirst=false;localConnection.send(CONNECTION_ID, "connected");
	var	timer:Timer=new Timer(SIGN);
		timer.addEventListener(TimerEvent.TIMER,sendSign);
		timer.start();
}
// Events ##################################################
//
private	static	function	sendSign(event:TimerEvent):void{localConnection.send(CONNECTION_ID,'Sign');}
private	static	function	onAsyncError(e:AsyncErrorEvent):void
{
	trace('	AsyncError		'+e.target+e.text);
}
private	static	function	onSecurityError(e:SecurityErrorEvent):void
{
	trace('	SecurityError	'+e.target+e.text);
}
private	static	function	onStatus(e:StatusEvent):void
{
	if(e.level=='status'||e.level=='error'){return;}
	trace('	onStatus		'+e.target+'	'+e.type+'	'+e.level);
}
// END #####################################################
}	//class
}	//package
// END #####################################################